package com.pojoin.cms.service.impl;

import java.util.List;

import com.pojoin.cms.dao.RoleDao;
import com.pojoin.cms.domain.Role;
import com.pojoin.cms.service.RoleService;
import com.pojoin.cms.util.criteria.orderby.Orderby;
import com.pojoin.cms.util.criteria.orderby.OrderbyCost;
import com.pojoin.cms.util.pager.Pager;

public class RoleServiceImpl implements RoleService {
	
	private RoleDao roleDao;

	public RoleDao getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}


	@Override
	public List<Role> getAllRoles() {
		return this.roleDao.search(null, null);
	}

	@Override
	public Role add(Role role) {
		if(!this.roleDao.isExistRole(role)){
			return this.roleDao.addRole(role);
		}
		return null;
	}

	@Override
	public Role findById(Long roleId) {
		return this.roleDao.findRoleById(roleId);
	}

	@Override
	public List<Role> listAllRoles(Pager pager) {
		Orderby o = new Orderby("roleId", OrderbyCost.DESC);
		return this.roleDao.search(null, o, pager);
	}

}
